package cn.kgc.itrip.auth.controller;

import cn.kgc.itrip.auth.service.TokenService;
import cn.kgc.itrip.beans.common.ServerResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * @author 阿泽
 */
@Controller
@RequestMapping(value = "/api")
public class TokenController {
    @Resource
    private TokenService tokenService;
    @RequestMapping(value = "/retoken", method = RequestMethod.POST,
            produces = "application/json")
    @ResponseBody
    public ServerResponse Replace(HttpServletRequest request) {
        String agent = request.getHeader("user-agent");
        String token = request.getHeader("token"); //从请求中获取token
      return tokenService.ReplaceToken(agent, token);//置换一个新的Token
    }
}